package com.example.springcloud.cfgbeans;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RetryRule;

@Configuration
public class ConfigBean {

	/**
	 * @LoadBalanced：使用客户端负载均衡SpringCloudRibbon
	 * @return
	 */
	@Bean
	@LoadBalanced
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}
	
	@Bean
	public IRule myRule() {
		return new RetryRule();
	}
	
	/**
	 * 不能同时注册两个及以上IRule实例，否则报错：available: expected single matching bean but found 2: myRule,myRule2"
	 */
//	@Bean
//	public IRule myRule2() {
//		return new RoundRobinRule();
//	}
	
}
